package com.niodata.dp.web.module.task;

import com.niodata.dp.core.exception.ErrorCodes;
import com.niodata.dp.log.LogUtil;
import com.niodata.dp.task.entity.FlowExecutor;
import com.niodata.dp.task.service.TaskManager;
import com.niodata.dp.web.module.base.BaseController;
import java.io.IOException;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/v1/executor")
@RestController
public class ExecutorController extends BaseController {

  private static final Logger logger = Logger.getLogger(ExecutorController.class);

  @Autowired
  @Qualifier("azTaskManager")
  private TaskManager taskManager;

  @RequestMapping("/view/list")
  public Object getAllExecutors() {
    List<FlowExecutor> flowExecutorList = null;
    try {
      flowExecutorList = taskManager.getFlowExecutors();
    } catch (IOException e) {
      LogUtil.logStackTrace(logger, e);
      return getError(ErrorCodes.ERROR_TASK, "azkaban error");
    }
    return getResult(flowExecutorList);
  }

}
